feat: add get_current_state workflow query to BaseWorkflow#292
Open
feat: add get_current_state workflow query to BaseWorkflow#292
Conversation
619b140 to
53807f2
Compare
Adds a default @workflow.query handler named "get_current_state"
to BaseWorkflow. Returns "unknown" by default — agents override
to report their actual state.
Example for StateMachine-based agents:
@workflow.query(name="get_current_state")
def get_current_state(self) -> str:
return self.state_machine.get_current_state()
Companion to scaleapi/scale-agentex#173 which adds
GET /tasks/{task_id}/query/{query_name} endpoint.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
53807f2 to
01391e0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a default
@workflow.queryhandler namedget_current_statetoBaseWorkflow, enabling external callers to query an agent's current workflow state via Temporal queries.Problem
When programmatically invoking agentic agents in multi-turn conversations, there's no way to know when the agent has finished processing a turn. The task stays
RUNNINGthroughout. During long-running operations (e.g. deep research), agents emit multiple progress messages that look like responses but aren't the final answer.Solution
Add a
get_current_statequery toBaseWorkflowthat returns the workflow's current state string. By default it returns_workflow_state(set to"initialized").Agents using the
StateMachineSDK should override this to return the actual state:This enables callers to detect
"waiting_for_input"— the definitive signal that the agent has finished its turn.Companion PR
GET /tasks/{task_id}/query/{query_name}to the Agentex REST APITogether, these changes enable:
Follows the pattern of Google A2A protocol's
INPUT_REQUIREDtask state.🤖 Generated with Claude Code
Greptile Summary
This PR adds a
get_current_stateTemporal query handler toBaseWorkflow, enabling external callers to poll the workflow's current state via the forthcomingGET /tasks/{task_id}/query/{query_name}REST endpoint. The base implementation returns"unknown", with documentation showing howStateMachine-based subclasses should override it to expose meaningful states like"waiting_for_input".Key changes:
@workflow.query(name="get_current_state")toBaseWorkflowreturning"unknown"by default.StateMachine-based agents so they can return the actual state machine state._workflow_statenever being updated is resolved — the final implementation drops the attribute entirely and simply returns"unknown".temporal/project/workflow.py.j2andtemporal-openai-agents/project/workflow.py.j2) are not updated here; agents generated from those templates will always return"unknown"until they explicitly override this method.Confidence Score: 5/5
"unknown"return is honest and non-breaking; callers that don't yet use this query are unaffected. The docstring clearly guides subclass authors on the correct override pattern including re-applying the@workflow.querydecorator, consistent with how@workflow.signaloverrides are already handled in the templates.Important Files Changed
get_current_stateTemporal query handler toBaseWorkflowreturning"unknown"by default, with documentation showing howStateMachine-based subclasses should override it.Sequence Diagram
sequenceDiagram participant Caller as External Caller participant Agentex as Agentex API participant Temporal as Temporal Worker participant WF as Workflow (BaseWorkflow subclass) participant SM as StateMachine (optional) Caller->>Agentex: GET /tasks/{task_id}/query/get_current_state Agentex->>Temporal: QueryWorkflow("get_current_state") Temporal->>WF: get_current_state() alt StateMachine-based workflow WF->>SM: get_current_state() SM-->>WF: "waiting_for_input" / "researching" / ... else Base/non-SM workflow WF-->>WF: return "unknown" end WF-->>Temporal: state string Temporal-->>Agentex: result Agentex-->>Caller: {"result": "waiting_for_input"}Reviews (4): Last reviewed commit: "feat: add get_current_state workflow que..." | Re-trigger Greptile